package com.demo.register;

import com.demo.domain.Cat;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyRegister implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //1、通过Bd工具类生成bd对象，只是这个Db对象比较纯洁没有绑定任何类
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition();
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) beanDefinitionBuilder.getBeanDefinition();
        //2、设置bd绑定的类型
        beanDefinition.setBeanClass(Cat.class);
        //3、注册到spring容器中
        registry.registerBeanDefinition("registerBeanDefinitions&&Cat",beanDefinition);
    }
}
